package com.kgcx.common.rabbitmq.bean;


import com.xiaoleilu.hutool.util.RandomUtil;

import java.io.Serializable;

public class Message implements Serializable {

    private static final long serialVersionUID = -295123815695940734L;
    public static final Integer FLAG_ADD = 1;
    public static final Integer FLAG_UPDATE = 2;
    public static final Integer FLAG_DELETE = 3;

    /**
     * 消息编号,建议使用uuid
     */
    private String id;
    /**
     * 消息类型
     */
    private String type;
    /**
     * 保留参数c
     */
    private Object params;
    /**
     * 消息内容
     */
    private Object body;
    /**
     * 消息创建时间
     */
    private String createTime;
    /**
     * 1=新增，2=更新，3=删除
     */
    private Integer flag;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Object getParams() {
        return params;
    }

    public void setParams(Object params) {
        this.params = params;
    }

    public Object getBody() {
        return body;
    }

    public void setBody(Object body) {
        this.body = body;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public Integer getFlag() {
        return flag;
    }

    public void setFlag(Integer flag) {
        this.flag = flag;
    }

    public static Message buildMessage(String type, Integer flag, Object body) {
        Message msg = new Message();
        msg.setType(type);
        msg.setFlag(flag);
        msg.setId(RandomUtil.randomUUID());
        msg.setBody(body);
        msg.setCreateTime(System.currentTimeMillis() + "");
        return msg;
    }

}
